
import '../helper/Helper.dart';
import '../helper/dioHelper2.dart';

class Report {
  int ID;
  String Guid;
  String SpaceId;
  String Title;
  String Content;
  String UserId;
  String CreateTime;

  Report(this.ID, this.Guid, this.SpaceId, this.Title, this.Content,
      this.UserId, this.CreateTime);
  Report.fromJson(Map<String, dynamic> json)
      : ID = json["ID"],
        Guid = json["Guid"],
        SpaceId = json["SpaceId"],
        Title = json["Title"],
        Content = json["Content"],
        UserId = json["UserId"],
        CreateTime =Helper.DateTimeFormat(json["CreateTime"]);
  Map<String, dynamic> toJson() => {
        'ID': ID,
        'Guid': Guid,
        'SpaceId': SpaceId,
        'Title': Title,
        'Content': Content,
        'UserId': UserId,
        'CreateTime': Helper.DateTimeFormat(CreateTime),
      };
  static Future<bool> Add(Report x1) async {
    var response = await DioHelper.Post("/Report/Add", x1.toJson());
    if (response.statusCode == 200) return true;
    return false;
  }

  static Future<bool> Update(Report x1) async {
    var response = await DioHelper.Post("/Report/Update", x1.toJson());
    if (response.statusCode == 200) return true;
    return false;
  }

  static Future<bool> Delete(Report x1) async {
    var st = x1.toJson();
    var response = await DioHelper.Post("/Report/Delete", x1.toJson());
    if (response.statusCode == 200) return true;
    return false;
  }

  static Future<Report?> Get(String where, dynamic data) async {
    var response = await DioHelper.Post("/Report/GetByWhere", {
      "Where": where,
      "obj": data,
    });

    if (response.statusCode == 200) return new Report.fromJson(response.data);
    return null;
  }

  

  static Future<List<Report>> GetList(String id,int pageIndex, int pageSize) async {
    String p1=pageIndex.toString();
    String ps=pageSize.toString();

    var response = await DioHelper.Get("/Report/GetList?SpaceId=$id&p1=$p1&ps=$ps", {  
    });

    var list1 = <Report>[];
    if (response.statusCode == 200) {
      if(response.data==null)
      return list1;
      for (var x in response.data) {
        list1.add(new Report.fromJson(x));
      }
    }
    return list1;
  }


}
